package com.es;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

/**
 * 描述:
 * MyBatis-
 *
 * @author Derek
 * 创建时间：2022-05-07 10:28
 */
public class SqlSessionUtils {
    public static SqlSession getSqlSession(){
        try {
            Reader reader = Resources.getResourceAsReader("mybatis-config.xml");
            SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
            SqlSessionFactory factory = builder.build(reader);
            return factory.openSession(true);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }

    public static void main(String[] args) {
        System.out.println(SqlSessionUtils.getSqlSession());
        System.out.println(OpEnum.getOpEnum(101));
    }
}
